package com.xhwl.centiotdata.pojo.dto.brodcast;

import com.alibaba.fastjson.JSONObject;
import com.xhwl.common.enums.CategoryEnum;
import com.xhwl.common.pojo.cent.device.DeviceProjSupplierCategory;
import lombok.Data;

import java.util.Objects;

/**
 * @author pengjunming
 * @description
 * @date 2022/10/8 9:45
 */
@Data
public class PhonogramConfigDTO {

    private Integer projectId;

    private Integer productId;

    private String ipAndPort;

    private String loginName;

    private String password;

    private Integer deviceType;

    private CategoryEnum categoryEnum;

    private Integer categoryId;

    private String ak;

    private String sk;

    private String tagId;

    public static PhonogramConfigDTO toPhonogramConfig(DeviceProjSupplierCategory supplierCategory) {
        PhonogramConfigDTO dto = new PhonogramConfigDTO();
        JSONObject properties = supplierCategory.getProperties();
        if (Objects.nonNull(properties)) {
            dto = properties.toJavaObject(PhonogramConfigDTO.class);
        }
        dto.setProductId(supplierCategory.getProductId());
        dto.setProjectId(supplierCategory.getProjectId());
        dto.setCategoryId(supplierCategory.getProdCategoryId());
        return dto;
    }
}
